<html>
<head>
<title>DIGI-Infomat</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
<link href="style.css" rel="stylesheet" type="text/css">
    <style type="text/css">
        .style1
        { width: 20%;}
    </style>
        <script type="text/javascript">
    function isNum(str)
    {
        var reg=/^[0-9]*$/;
        
        if(!reg.test(str))
            return false;
        else
            return true;
    }
    function changeVolume(flag)
    {
        var txtVolume=document.getElementById("txtVolume");
        var volume=0;
        
        if(isNum(txtVolume.value)) volume=parseInt(txtVolume.value);
        
        if(flag=="-") volume=volume-1;
        else volume=volume+1;
        
        if(volume<0) volume=0;
        if(volume>100) volume=100;        
        
        txtVolume.value=volume;       
        
    }
    </script>
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" style="text-align:center">
<?php 
	include "xbootconf.php"; 
	include "xutility.php";
	$xBootConf = new XBootConf();
	$xUtility = new XUtility();	
	if (!empty($_POST)) {
       $btn = $_POST['btn'];  
	   	//echo '<pre>';
		//print_r($_POST);
		//echo "<br/>";

	   switch ($btn)
	   {
		case "save":
			/************** Layout ****************/
			$selectedLayout = $_POST['ddLayout'];
			preg_match('/Layout(\d+)/', $selectedLayout, $matches);
			$layout = $matches[1];
			if ($layout  < 1  || $layout > 13) {
				echo "[NG] Wrong Layout Value";
				return;
			}
			
			if ($layout > 5) {
				$layout = $layout + 2;
			}
			
			$xBootConf->writeLayout($layout);
		
			/************** volume ****************/
			$volume = $_POST['txtVolume'];
			if ($volume < 0)
				$volume = 0;
			if ($volume > 100) 
				$volume = 100;
			$xBootConf->writeVolume($volume);
			
			/******** Screen Switching ***********/
			if (isset($_POST['chkScreenSwitch'])) {
				$xBootConf->writeScreenSwitch(1);
			}  else  {
				$xBootConf->writeScreenSwitch(0);
			}
			
			/******** Default Timeout ***********/
			$timeout = $_POST['txtTimeout'];
			if ($timeout <0) 
				$timeout = 0;
			if ($timeout > 99) 
				$timeout = 99;
			$xBootConf->writeTimeout($timeout);
			
			/******** Discount Message ***********/
			if (isset($_POST['chkDiscountMessage'])) {
				$xBootConf->writeDiscountMessage(1);
			}  else  {
				$xBootConf->writeDiscountMessage(0);
			}
			break;
			
		case "reset default":
			$xUtility->setDefault();
			$xBootConf->readBootConf();
			break;
		case "reboot":
			$xUtility->reboot();
			break;
	   }
	}
					
?>
<form name="settingForm" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table width="100%"> 
<tr>
   <td align="center">
        <table width="780px" border="0" cellspacing="0" cellpadding="0">
            <tr>
                <td>
                    <table border="0" bgcolor="#FFFFFF" width="100%">
                       <tr>
                            <td rowspan="2" width="20%"><img src="images/logo.png" alt="logo"></td>
                        </tr>
                           
                       <tr valign="bottom"  align="center">
                            <td><a href="home.php"><img src="images/btn_home.png" style="border-width:0px;" alt="HOME"></a></td>
                            <td><a href="network.php"><img style="border-width:0px;" src="images/btn_network.png" alt="Network Setting"></a></td>
                            <td><a href="update.php"><img style="border-width:0px;" src="images/btn_update.png" alt="Update"></a></td>
                             <td><a href="setting.php"><img style="border-width:0px;" src="images/btn_setting.png" alt="Maintenance"></a></td>
                             <td><a href="filemanage.php"><img style="border-width:0px;" src="images/btn_filemanage.png" alt="File Manage"></a></td>
                        </tr>
                    </table>
               	</td>
            </tr> 
				<tr>
                    <td colspan="2">
						<table border="0" cellspacing="0" cellpadding="0"></table>
					</td>
				</tr>
            <tr>
            	<td colspan="2" valign="middle" bgcolor="#FFFFFF">
		    <table border="0" cellspacing="0" cellpadding="0"  width="780px" class="form_table">
				<tr>
					     	<td width="3%">&nbsp;</td>
                             <td valign="middle" class="name" width="25%" ><strong class="green-text">Maintenance Page</strong></td>
                            <td colspan="2" width="50%">&nbsp;</td>
                            <td colspan="2" rowspan="5" align="top" class="red-text-regular">The new settings will be effective since next reboot infomat.</td>
                      	</tr>
                        
                        <tr>
                            <td width="3%">&nbsp;</td>
                            <td valign="middle"><strong>Layout</strong></td>
                            <td colspan="2">
                            <?php
							$isSelected = array(0=>"", 1=>"", 2=>"", 3=>"", 4=>"",5=>"",
											    6=>"", 7=>"", 8=>"", 9=>"", 10=>"", 11=>"", 12=>"");   //drop 2 items
							$layout = $xBootConf->getLayout();
        					if ( $layout > 0 && $layout  < 13) {
            					$isSelected[$layout -1] = "selected";
        					} else {
								echo "[NG] Layout Value is invalid".$this->_layout;
								return;
							}
							?>
        
        				<select name="ddLayout">
        					<option <?php echo $isSelected[0] ?> >Layout1 : WM + Video + Html</option>
       						<option <?php echo $isSelected[1] ?> >Layout2 : WM + Video</option>
       						<option <?php echo $isSelected[2] ?> >Layout3 : Video Only</option>
        					<option <?php echo $isSelected[3] ?> >Layout4 : WM + Html</option>
       						<option <?php echo $isSelected[4] ?> >Layout5 : Html Only</option>
        					<option <?php echo $isSelected[7] ?> >Layout6 : Queue + Video</option>
        					<option <?php echo $isSelected[8] ?> >Layout7 : Queue Display</option>
        					<option <?php echo $isSelected[9] ?> >Layout8 : Queue + WM + Video</option>
        					<option <?php echo $isSelected[10] ?> >Layout9 : Queue + WM + Html</option>
        					<option <?php echo $isSelected[11] ?> >Layout10 : Queue + WM</option>
        				</select>
							
                            </td>
                        </tr>
                       
                        <tr>
                            <td style="no">&nbsp;</td>
                            <td valign="middle" class="name" ><strong>Volume</strong></td>
			    		<td colspan="2" valign="middle">
                        <input align="middle" maxlength="3" name="txtVolume" type="text" value="<?php echo ($xBootConf->getVolumePercent());?>" style="width:30px"/>
                        % (0%~100%)</td>
               		  </tr>
                      
			<tr>
                            <td style="no">&nbsp;</td>
                       	    <td valign="middle" ><strong>Screen Switching</strong></td>
                            <td colspan="2">
                            <input type="checkbox" name="chkScreenSwitch" value="yes" id="chkScreenSwitch" 
							<?php
								if ($xBootConf->getScreenSwitch() == 1) {
								echo "checked";
								} else {
								echo "";
								}
							?>>
                            </td>
              </tr>
                      
			<tr>
                            <td style="no">&nbsp;</td>
                            <td valign="middle" class="name" style="width: 15%"><strong>Default Timeout</strong></td>
                            <td colspan="2">
                            <input type="text" maxlength="3" name="txtTimeout"  style="width:30px" value=" <?php echo $xBootConf->getTimeout();?>"> 
                            Seconds
                            (0-99)</td>
              </tr>
            <tr>
                            <td style="no">&nbsp;</td>
                            <td ><strong>Discount Message</strong></td>
                            <td colspan="2">
                            <input type="checkbox" name="chkDiscountMessage" 
							<?php
							if (1==$xBootConf->isSetDiscount()) 
							echo "checked";
							else 
							 	echo "";  
							?> > 
                            </td>
                            <td colspan="2" align="right">&nbsp;</td>
			</tr>
            <tr>
              <td >&nbsp;</td>
              <td style="name" >&nbsp;</td>
              <td colspan="2">&nbsp;</td>
              <td colspan="2" align="right">&nbsp;</td>
            </tr>
            <tr>
              <td>&nbsp;</td>
              <td ><input type="submit" name="btn" value="save" id="save"  /></td>
              <td colspan="2"><input type="submit" name="btn" value="reset default" id="reset_default"  /></td>
              <td colspan="2" align="right"><input type="submit" name="btn" value="reboot" id="reboot" /></td>
            </tr>
		    </table>
		</td>
            </tr>
	    <tr>
		<td colspan="2" align="center" class="white-text">
		    <table width="100%" border="0" cellspacing="0" cellpadding="10">
			<tr>
			<td align="center" class="white-text">Copyright &copy;  Teraoka Weigh System. All Rights Reserved.</td>
			</tr>
		    </table>
		</td>
	    </tr>
	</table>
   </td>
</tr>
</table>
</form>

</body>
</html>